<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<script type="text/javascript">
	function savePwd(){
		$('#changepassword_form').isValid(function(v) {
			if(v){
				var l_password = $('#l_password').val();
				var l_new_password = $('#l_new_password').val();
		        var l_q_new_password = $('#l_q_new_password').val();
		        if(l_password!=null&&l_password!=""&&l_new_password!=null&&l_new_password!=""&&l_q_new_password!=null&&l_q_new_password!=""){
		            if(l_password==l_new_password){
		            	$('#changepassword_form').alertmsg('error', "新密码和原密码不能相同！");
		            	return;
		             }
		             if(l_new_password.length<8){
		            	 $('#changepassword_form').alertmsg('error', "新密码长度不能低于8位！");
			            	return;
			         }
		            
		            if(validPwd(l_new_password)==false){
		            	$('#changepassword_form').alertmsg('error', "密码必须由数字加上字母组成！");
			            return;
			         } 
		            if(l_new_password!=l_q_new_password){
		            	$('#changepassword_form').alertmsg('error', "新密码两次输入不一致！");
		            	return;
		            }
		        }

		        var url = 'changePasswd/update.do';
        		var data = $('#changepassword_form').serialize();
        		var successCallBack = function(result){
        			$('#changepassword_form').alertmsg('info', result.message);
					$('#changepassword_form').dialog('closeCurrent');
        		}
        		var failCallBack = null;
        		var errorCallBack = null;
        		myAjax(url, data, true, successCallBack, failCallBack, errorCallBack);
			}
		});
		

}
     function closePwd(){
    	 $('#changepassword_form').dialog('closeCurrent');
     }
     
     function validPwd(password) {  
         var num = 0;  
         var number = 0 ;  
         var letter = 0 ;  
         var bigLetter = 0 ;  
         var chars = 0 ;  
           
         if (password.search(/[0-9]/) != -1) {  
             num += 1;  
             number =1;  
         }  
         if (password.search(/[A-Z]/) != -1) {  
             num += 1;  
             bigLetter = 1 ;  
         }  
         if (password.search(/[a-z]/) != -1) {  
             num += 1;  
             letter = 1 ;  
         }  
         
         if(number>=1&&(bigLetter+letter<=0)){  
                 //alert("不能全为数字!");  
             return false;
         }  
         if(number==0&&(bigLetter+letter>=1)){
             //alert("不能全为字母!");
        	 return false;
          }
         var reg = /^[0-9a-zA-Z]+$/;
         if(!reg.test(password)){
            // alert("密码只能由数字和字母组成");
        	 return false;
         }
         return true;
     }  
</script>
<div class="bjui-pageContent">
	<form dataValue="" id="changepassword_form" data-toggle="validate" data-alertmsg="false">
        <table class="table table-condensed" width="100%">
            <tbody>
                <tr>
                    <td style="width: 140px;text-align: right;">
                        <label for="l_dataType" class="control-label x100">原密码：</label>
                    </td>
                    <td>
                        <input type="password" name="password" id="l_password" data-rule="required;length[~32];jsvalide" size="28">
                    </td>
                </tr>
                <tr>
                    <td style="width: 140px;text-align: right;">
                        <label for="l_dataName" class="control-label x100">新密码：</label>
                    </td>
                    <td>
                        <input type="password" name="newPassword" id="l_new_password" value="" data-rule="required;length[~20];jsvalide" size="28">
                    </td>
                </tr>
                <tr>
                    <td style="width: 140px;text-align: right;">
                        <label for="l_dataValue" class="control-label x100">确认新密码：</label>
                    </td>
                    <td>
                        <input type="password" name="confirmPassword" id="l_q_new_password" value="" data-rule="required;length[~20];jsvalide" size="28">
                    </td>
                </tr>
            </tbody>
        </table> 
    </form>
</div>
<div class="bjui-pageFooter">
	<ul>
		<li><button type="button" class="btn btn-red cancel" onclick = "closePwd()"data-icon="remove">取消</button></li>
		<li><button type="button" class="btn btn-default save" onclick = "savePwd()" data-icon="save">保存</button></li>
	</ul>
</div>